#include <QtGui>
#include "doccontrol.h"

DocControl::DocControl(QWidget* parent):
  QWidget(parent)
{
  incident = new QButtonGroup();
  emergent = new QButtonGroup();
  zoom = new QButtonGroup();
  filterGroup = new QButtonGroup();

  QVBoxLayout* vbox = new QVBoxLayout;
  QPushButton* button = new QPushButton(tr("snapshot"));

  //QWidget* content;
  QGridLayout* content;
  QGroupBox* groupBox;
	QStringList sl;
	sl.clear();
	sl<< tr("None") <<tr("Green") << tr("Red")
		<< tr("White") <<tr("Blue") << tr("850")
		<< tr("730") <<tr("400-410") << tr("Left");
  content = addButtonGroup(incident, 3, sl);
  //addItem(content,tr("incident"));
  groupBox = new QGroupBox(tr("incident"));
  groupBox->setLayout(content);
  vbox->addWidget(groupBox,3);
  connect(incident, SIGNAL(buttonClicked(int)), this, SLOT(selectIncident(int)));

	sl.clear();
	sl<< tr("None") <<tr("Red") << tr("Yellow");
  content = addButtonGroup(emergent, 3, sl);
  //addItem(content,tr("emergent"));
  groupBox = new QGroupBox(tr("emergent"));
  groupBox->setLayout(content);
  vbox->addWidget(groupBox,1);
  connect(emergent, SIGNAL(buttonClicked(int)), this, SLOT(selectEmergent(int)));
	
  sl.clear();
  sl<< tr("None") <<tr("Red") << tr("Green")<<tr("Blue");
  content = addButtonGroup(filterGroup, 4, sl);
  //addItem(content,tr("emergent"));
  groupBox = new QGroupBox(tr("filter"));
  groupBox->setLayout(content);
  vbox->addWidget(groupBox,1);
  connect(filterGroup, SIGNAL(buttonClicked(int)), this, SLOT(selectFilter(int)));

  	sl.clear();
	sl<< tr("0") <<tr("1") << tr("2")
		<< tr("3") <<tr("4") << tr("5")
		<< tr("6") <<tr("7") << tr("8");
  content = addButtonGroup(zoom, 3, sl);
  //addItem(content,tr("zoom"));
  groupBox = new QGroupBox(tr("zoom"));
  groupBox->setLayout(content);
  vbox->addWidget(groupBox,3);
  vbox->addWidget(button);
  vbox->addStretch(4);
  connect(button, SIGNAL(clicked(bool)), this, SLOT(snap(bool)));
  connect(zoom, SIGNAL(buttonClicked(int)), this, SLOT(selectZoom(int)));
  setLayout(vbox);
}

void DocControl::selectIncident(int id)
{
	emit setIncident(id);
}

void DocControl::selectFilter(int id)
{
	emit setFilter(id);
}

void DocControl::snap(bool checked)
{
	emit snapshot();
}

void DocControl::selectEmergent(int id)
{
   emit setEmergent(id);
}

void DocControl::selectZoom(int id)
{
	emit setFactor(1.75+id*0.25);
}

/*QWidget*/QGridLayout* DocControl::addButtonGroup(QButtonGroup* group, int cols, QStringList& sl)
{
	int count = sl.size();
	int i, col=0,row=0;
	//QVBoxLayout *box=new QVBoxLayout;
	QGridLayout* grid = new QGridLayout;
	//QWidget* content = new QWidget;
	QPushButton *pb;

	for(i=0;i<count;i++){
		pb = new QPushButton(sl.at(i));
		pb->setCheckable(true);
		if(i==0)pb->setChecked(true);
		group->addButton(pb);
		group->setId(pb,i);
		grid->addWidget(pb,row,col);
		col++;
		if(col==cols){
			col = 0;
			row++;
		}
	}
	//box->addLayout(grid);
	//box->addStretch();
	//content->setLayout(box);
	//return content;
	return grid;
}
